<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCheckStreamsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('check_streams', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('tradeTime')->default(0)->comment('交易时间');
            $table->string('orderId', 64)->default('')->comment('业务订单编号');
            $table->string('subject', 64)->default('')->comment('订单摘要');
            $table->unsignedSmallInteger('sysType')->default(0)->comment('订单类型');
            $table->unsignedInteger('orderPrice')->default(0)->comment('订单金额，分');
            $table->unsignedInteger('tradePrice')->default(0)->comment('交易金额，分');
            $table->unsignedInteger('incomePrice')->default(0)->comment('入账金额，分');
            $table->unsignedInteger('feePrice')->default(0)->comment('手续费');
            $table->double('feeRate', 8, 6)->default(0)->comment('手续费率');
            $table->string('thirdPayNo', 64)->default('')->comment('第三方交易流水');
            $table->unsignedSmallInteger('company')->default(0)->comment('公司id');
            $table->string('companyAccount', 32)->default('')->comment('收款商户号/收款账户');
            $table->string('payNo', 64)->default('')->comment('支付/交易流水号');
            $table->unsignedSmallInteger('payChannel')->default(0)->comment('支付渠道 1支付宝 2微信 3现金 4富有 5银行转账');
            $table->unsignedSmallInteger('payChannelChild')->default(0)->comment('底层支付渠道 1支付宝 2微信');
            $table->unsignedTinyInteger('payAction')->default(0)->comment('支付操作类型 1用户主扫 2用户被扫 3 小程序支付');
            $table->unsignedTinyInteger('checkStatus')->default(0)->comment('对账状态 1未对账 2正常 3待审核 4异常');
            $table->string('errorReason', 64)->default('')->comment('异常原因');
            $table->string('remark', 64)->default('')->comment('备注');
            $table->json('payPic')->nullable()->comment('凭证图片json');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');

            $table->index('orderId', 'idxOrderId');
            $table->index('payNo', 'idxPayNo');
            $table->index('thirdPayNo', 'idxThirdPayNo');
            $table->index('tradeTime', 'idxTradeTime');

            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '对账 - 流水明细表';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('check_streams');
    }
}
